@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('admin.administrator.index')}}"><h5 class="content-header-title">管理员列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('admin.administrator.create')}}"><h5 class="content-header-title">添加管理员</h5></a>
            </div>
        </div>
        <div class="content-body">
            <div class="card">
                <div class="card-body table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>管理员编号</th>
                            <th>管理员名</th>
                            <th>管理员头像</th>
                            <th>账号</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                       @foreach($administrators as $administrator)
                            <tr>
                                <td class="mr-auto mt-auto" scope="row">{{$administrator->id}}</td>
                                <td class="mr-auto mt-auto">{{$administrator->name}}</td>
                                <td class="mr-auto mt-auto">
                                    <img style="width: 100px;height: 100px;border-radius: 50%;" src="{{$administrator->icon}}" alt="">
                                </td>
                                <td class="mr-auto mt-auto" scope="row">{{$administrator->phone?$administrator->phone:''}}/{{$administrator->email?$administrator->email:''}}</td>
                                <td class="mr-auto mt-auto">
                                    <a href="{{route('admin.administrator.edit',$administrator)}}"><button type="button" class="btn btn-info ">编辑</button></a>
                                    <button onclick="del(this)" type="button" class="btn btn-danger">删除</button>
                                    <form action="{{route('admin.administrator.destroy',$administrator)}}" method="post">
                                        @csrf @method('DELETE')
                                    </form>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@push('js')
    <script>
        function del(obj) {
            swal({
                title: '确定删除吗？',
                text: '你将无法恢复它！',
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定删除！',
                cancelButtonText: '取消删除！',
                confirmButtonClass: 'btn btn-success',
                cancelButtonClass: 'btn btn-danger',
                buttonsStyling: false
            }).then(function(value) {
                if(value.value){
                    $(obj).next('form').submit();
                }
            })

        }
    </script>
@endpush
